﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Honestysoft.Financing.Model
{
    public partial class BD_Project
    {
        /// <summary>
        /// 项目单位名称
        /// </summary>
        public string Owner971Name { get; set; }
        /// <summary>
        /// 建设单位名称
        /// </summary>
        public string OwnerName { get; set; }
        /// <summary>
        /// 委托代建单位名称
        /// </summary>
        public string DOwnerName { get; set; }

        /// <summary>
        /// 资本金变动情况
        /// </summary>
        public List<BD_ProjectZBJChange> ZBJChanges { get; set; }

        /// <summary>
        /// 新增资本金
        /// </summary>
        public List<BD_ProjectAddInvestment> AddInvesments { get; set; }
        /// <summary>
        /// 概算变动情况
        /// </summary>
        public List<BD_ProjectBudget> Budgets { get; set; }
        /// <summary>
        /// 最后概算
        /// </summary>
        public decimal LastBudget
        {
            get
            {
                if (Budgets == null || Budgets.Count == 0)
                {
                    return Investment;
                }
                else
                {
                    Budgets = Budgets.FindAll((BD_ProjectBudget find) => find.dataState != EnumItem.DataState.Delete);                    
                    if (Budgets == null || Budgets.Count == 0)
                    {
                        return 0;
                    }
                    else
                    {
                        Budgets.Sort(
                        delegate(BD_ProjectBudget v1, BD_ProjectBudget v2)
                        {
                            if (DateTime.Compare(v2.ChangeDate,v1.ChangeDate) == 0)
                            {
                                return DateTime.Compare(v2.CreateTime,v1.CreateTime);
                            }
                            else
                            {
                                return DateTime.Compare(v2.ChangeDate,v1.ChangeDate);
                            }
                        });
                        return Budgets[0].ChangeMoney;
                    }
                }
            }
        }
        /// <summary>
        /// 变更前概算
        /// </summary>
        public decimal BGQBudget
        {
            get
            {
                if (Budgets == null || Budgets.Count == 0)
                {
                    return Investment;
                }
                else
                {
                    Budgets = Budgets.FindAll((BD_ProjectBudget find) => find.dataState != EnumItem.DataState.Delete);
                    if (Budgets == null || Budgets.Count == 0)
                    {
                        return 0;
                    }
                    else
                    {
                        Budgets.Sort(
                        delegate(BD_ProjectBudget v1, BD_ProjectBudget v2)
                        {
                            if (DateTime.Compare(v2.ChangeDate, v1.ChangeDate) == 0)
                            {
                                return DateTime.Compare(v2.CreateTime, v1.CreateTime);
                            }
                            else
                            {
                                return DateTime.Compare(v2.ChangeDate, v1.ChangeDate);
                            }
                        });
                        return Budgets[0].SourceMoney;
                    }
                }
            }
        }

        /// <summary>
        /// 国开行贷款额度
        /// </summary>
        public List<BD_ProjectGKLoanAmount> GKLoanAmounts { get; set; }
        /// <summary>
        /// 年度投资计划
        /// </summary>
        public List<BD_ProjectInvestmentPlan> YearPlans { get; set; }
        /// <summary>
        /// 项目投资计划
        /// </summary>
        public List<BD_ProjectLoanAmount> LoanAmounts { get; set; }
        /// <summary>
        /// 参建单位
        /// </summary>
        public List<BD_ProjectCompany> Companys { get; set; }

        private EnumItem.DataState _dataState = EnumItem.DataState.Unchange;
        public EnumItem.DataState dataState
        {
            get { return _dataState; }
            set { _dataState = value; }
        }
    }
}
